import { Controller, Post, UploadedFile, UseInterceptors ,Request} from '@nestjs/common';
import { UploadService } from './upload.service';
import { Request as ExpRequest } from 'express';
import { FileInterceptor } from '@nestjs/platform-express';
import {  ApiTags } from '@nestjs/swagger';
import { isNoAuth } from 'src/utils/decorator/jwt.decorator';
@ApiTags('文件上传')
@Controller('upload')
@isNoAuth()
export class UploadController {
    constructor(private readonly uploadService: UploadService) {}

    @Post()
    @UseInterceptors(FileInterceptor('file'))
    async uploadFile(@UploadedFile() file: Express.Multer.File,@Request() req: ExpRequest): Promise<{ url: string }> {
      const fileUrl = await this.uploadService.uploadFile(file, req);
      return fileUrl;
    }
    
}
